<?php

namespace Wechat\Controller;

class AuditController extends CommonController {


    public function index() {
        $this->assign("access", check_role($this->customer["customer_id"], "1,4,7,8,10"));

        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $this->assign("user",$user);
        $this->display("index");
    }

    public function instoreList() {
        $id = $_REQUEST["id"];
        $orderStatus = $_REQUEST["status"];
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $this->assign("user", $user);
        $this->assign("orderId", $id);
        $this->assign("orderStatus", $orderStatus);
        $this->display("instoreList");
    }

    public function getInstoreList() {

//        $map["fo.status"] = array('neq','-3');
        $status = I("post.status");
        if(!isNullOrEmpty($status)) {
            $map["s#outstore_status"] = $status;
        }
        $startdate = I("post.startdate");
        $enddate = I("post.enddate");
        if (!isNullOrEmpty($startdate)) {
            $map["s#outstore_date-egt"] = $startdate;
        }
        if (!isNullOrEmpty($enddate)) {
            $map["s#outstore_date-elt"] = $enddate . " 23:59:59";
        }

        $month = I("post.month");
        if (!isNullOrEmpty($month)) {
            $map["s#outstore_date-egt"] = $month . "-01 00:00:00";
            $map["s#outstore_date-elt"] = $month . "-30 23:59:59";
        }

        $employee = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $map["s.enterprise_code"] = $employee["enterprise_code"];
        $list = D("Instore")->alias("s")
//            ->join("left join __ADMIN__ emp on emp.employee_id = s.update_id")
            ->join("left join __WORKORDER__ wo on wo.workorder_id = s.product_id")
            ->join("left join __PATIENT__ pt on pt.patient_id = wo.patient_id")
            ->join("left join __STORE__ st on st.store_id = s.store_id")
            ->join("left join __ADMIN__ sales on sales.employee_id = wo.sales_id")
            ->join("left join __ADMIN__ storeman on storeman.employee_id = wo.storeman_id")
            ->join("left join __ADMIN__ auditor on auditor.employee_id = s.outstore_auditor_id")
            ->where(getWhereSqlByMap($map))
            ->order("s.create_time desc")
//            ->limit()
            ->field("s.*, pt.patient_name, pt.sex, pt.age, sales.admin_name as sales_name, auditor.admin_name as auditor_name, storeman.admin_name as storeman_name, wo.workorder_no, wo.price, st.store_name, wo.payment_status, wo.deposit")
            ->select();

        echo json_encode($list);

    }

    public function auditWorkorder() {
        $status = I("post.status");
        $orderId = I("post.orderId");
        $data["code"] = 200;
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();

        $instoreData = D("Instore")->queryById($orderId);
        if($instoreData["status"] == $status){
            $data["message"] = "工单已审核过，无需重复审核。";
            echo json_encode($data);
            return;
        }
        $instoreData["outstore_status"] = $status;
        $instoreData["outstore_auditor_id"] = $user["employee_id"];
        $instoreData["outstore_audit_time"] = getCurrentDate();
        D("Instore")->updateInfo($instoreData);
        $workorder = D("Workorder")->queryById($instoreData["product_id"]);
        $sales = D("admin")->where(array('employee_id'=>$instoreData["employee_id"]))->find();
        if($status == 1) {
            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/audit/instoreList/?id=" . $instoreData["instore_id"] . "&status=2";
            $notifyData["first"] = "定制产品订单 [" . $instoreData["finished_order_no"] ."] 出库审核通过。";
            $notifyData["keyword2"] = "审核通过";
        }else{
            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/audit/instoreList/?id=" . $instoreData["instore_id"] . "&status=-1";
            $notifyData["first"] = "定制产品订单 [" . $instoreData["finished_order_no"] ."] 出库反审核。";
            $notifyData["keyword2"] = "反审核";
        }
        $notifyData["keyword1"] = $workorder["inventory_name"]."(".$instoreData["spec"] .")共 ".$instoreData["number"].$instoreData["unit"]."，[" . $instoreData["payment_status"] . "] ". $instoreData["payment_price"] ."元";
        $notifyData["keyword3"] = "财务审核人：" . $user["admin_name"] . "，业务员：" . $sales["admin_name"];
        $notifyData["keyword4"] = getCurrentDate();
        $notifyData["remark"] = null;
        $openidArray = getNotifyArrByName("auditWorkorder", $user["enterprise_code"]);
        array_push($openidArray, $user["openid"]);
        array_push($openidArray, $sales["openid"]);
        $openidArray = array_unique($openidArray);
        foreach ($openidArray as $openid) {
            $notifyData["openid"] = $openid;
            ApprovalResultNotify($notifyData);
        }
        echo json_encode($data);
    }

    public function auditWorkorderMonth() {
        $status = I("post.status");
        $month = I("post.month");
        $data["code"] = 200;
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();

        if (!isNullOrEmpty($month)) {
            $map["outstore_date-egt"] = $month . "-01 00:00:00";
            $map["outstore_date-elt"] = $month . "-31 23:59:59";
        }
        $map["outstore_status"] = -1;
        $map["enterprise_code"] = $user["enterprise_code"];
        $list = D("Instore")->where(getWhereSqlByMap($map))->select();
        if(sizeof($list) == 0){
            $data["message"] = "无可审核订单。";
            echo json_encode($data);
            return;
        }

        foreach ($list as $instoreData) {
            $instoreData["outstore_status"] = $status;
            $instoreData["outstore_auditor_id"] = $user["employee_id"];
            $instoreData["outstore_audit_time"] = getCurrentDate();
            D("Instore")->updateInfo($instoreData);
        }
        $notifyData["first"] = "定制产品订单 [" . $month ."月] 出库审核通过。";
        $notifyData["keyword1"] = "共 ".sizeof($list)."单";
        $notifyData["keyword2"] = "审核通过";
        $notifyData["keyword3"] = "财务审核人：" . $user["admin_name"];
        $notifyData["keyword4"] = getCurrentDate();
        $notifyData["remark"] = null;

        $openidArray = getNotifyArrByName("auditWorkorder", $user["enterprise_code"]);
        array_push($openidArray, $user["openid"]);
        $openidArray = array_unique($openidArray);
        foreach ($openidArray as $openid) {
            $notifyData["openid"] = $openid;
            ApprovalResultNotify($notifyData);
        }
        echo json_encode($data);
    }

    public function claimList() {
        $id = $_REQUEST["id"];
        $orderStatus = $_REQUEST["status"];
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $this->assign("user", $user);
        $this->assign("orderId", $id);
        $this->assign("orderStatus", $orderStatus);
        $this->display("claimList");
    }

    public function getClaimList() {

//        $map["fo.status"] = array('neq','-3');
        $status = I("post.status");
        if(!isNullOrEmpty($status)) {
            $map["wo#claim_status"] = $status;
        }else{
            $map["wo#claim_status-egt"] = -2;
        }
        $startdate = I("post.startdate");
        $enddate = I("post.enddate");
        if (!isNullOrEmpty($startdate)) {
            $map["wo#claim_date-egt"] = $startdate;
        }
        if (!isNullOrEmpty($enddate)) {
            $map["wo#claim_date-elt"] = $enddate . " 23:59:59";
        }
//
//        $month = I("post.month");
//        if (!isNullOrEmpty($month)) {
//            $map["s#outstore_date-egt"] = $month . "-01 00:00:00";
//            $map["s#outstore_date-elt"] = $month . "-30 23:59:59";
//        }

        $employee = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $map["wo.enterprise_code"] = $employee["enterprise_code"];
        $list = D("Workorder")->alias("wo")
//            ->join("left join __ADMIN__ emp on emp.employee_id = s.update_id")
//            ->join("left join __CLAIM_MATERIAL__ cm on cm.workorder_no = s.product_id")
            ->join("left join __PATIENT__ pt on pt.patient_id = wo.patient_id")
//            ->join("left join __STORE__ st on st.store_id = s.store_id")
            ->join("left join __ADMIN__ sales on sales.employee_id = wo.sales_id")
            ->join("left join __ADMIN__ claimer on claimer.employee_id = wo.claimer_id")
            ->join("left join __ADMIN__ auditor on auditor.employee_id = wo.claim_auditor_id")
            ->join("left join __STORE__ st on st.store_id = wo.material_store_id")
            ->where(getWhereSqlByMap($map))
            ->order("wo.create_time desc")
//            ->limit()
            ->field("wo.*, pt.patient_name, pt.sex, pt.age, st.store_name, sales.admin_name as sales_name, auditor.admin_name as auditor_name, claimer.admin_name as claimer_name")
            ->select();
        $newList = array();
        foreach ($list as $order){
            $claimList = D("ClaimMaterial")->alias("cm")
                ->join("left join __ADMIN__ emp on emp.employee_id = cm.update_id")
                ->join("left join __CODE__ c on c.code_id = cm.code_id")
                ->join("left join __CODE__ p on p.code_id = c.parentid")
                ->join("left join __MATERIAL__ m on m.code_id = cm.code_id")
                ->join("left join __STORE__ st on st.store_id = cm.store_id")
                ->join("left join __STORAGE__ stg on stg.batch_no = cm.batch_no and stg.enterprise_code = cm.enterprise_code and stg.code_id = cm.code_id and stg.store_id = cm.store_id")
                ->where(array('cm.workorder_no'=>$order["workorder_no"]))
                ->field("cm.*, emp.admin_name, c.name as code_name, p.name as parent_name, m.material_name, m.spec, m.prop, m.unit, m.barcode, st.store_name, stg.storage_id, stg.price as cost, stg.storage_number")
                ->select();
            $order["claimList"] = $claimList;
            array_push($newList, $order);
        }

        echo json_encode($newList);

    }

    public function auditClaim() {
        $status = I("post.status");
        $orderId = I("post.orderId");
        $data["code"] = 200;
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $data["message"] = $orderId;
        $workorderData = D("Workorder")->queryById($orderId);
        if($workorderData["claim_status"] == $status){
            $data["message"] = "工单已审核过，无需重复审核。";
            echo json_encode($data);
            return;
        }

        if($status == -2){

            $List = D("ClaimMaterial")->where(array('workorder_no'=>$workorderData["workorder_no"]))->select();
            foreach ($List as $tmpData){
                $tmpData["update_time"] = getCurrentDate();
                $tmpData["status"] = -1;
                D("ClaimMaterial")->updateInfo($tmpData);
                $tmpData["type"] = "物料";
                $tmpStorage = D("Storage")
                    ->where(array('type'=>'物料',
                        'enterprise_code'=>$user["enterprise_code"],
                        'code_id'=>$tmpData["code_id"],
                        'store_id'=>$tmpData["store_id"],
                        'batch_no'=>$tmpData["batch_no"]))
                    ->find();
                if(isNullOrEmpty($tmpStorage)){
                    $tmpData["storage_number"] = $tmpData["number"];
                    D("Storage")->add($tmpData);
                }else{
                    $tmpStorage["storage_number"] += $tmpData["number"];
                    $tmpStorage["update_time"] = getCurrentDate();
                    $tmpStorage["update_id"] = $user["employee_id"];
                    D("Storage")->updateInfo($tmpStorage);
                }
            }
        }


        $workorderData["claim_status"] = $status;
        $workorderData["claim_auditor_id"] = $user["employee_id"];
        $workorderData["claim_audit_date"] = getCurrentDate();
        D("Workorder")->updateInfo($workorderData);
        $patient = D("Patient")->queryById($workorderData["patient_id"]);
        $claimer = D("admin")->where(array('employee_id'=>$workorderData["claimer_id"]))->find();
        if($status == 1) {
            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/audit/claimList/?id=" . $workorderData["workorder_id"] . "&status=1";
            $notifyData["first"] = "定制产品领料单 [" . $workorderData["workorder_no"] ."] 审核通过。";
            $notifyData["keyword2"] = "审核通过";
        }else{
            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/audit/claimList/?id=" . $workorderData["workorder_id"] . "&status=-2";
            $notifyData["first"] = "定制产品领料单 [" . $workorderData["workorder_no"] ."] 反审核。";
            $notifyData["keyword2"] = "反审核";
        }
        $notifyData["keyword1"] = "患者：" . $patient["patient_name"] . " ".$workorderData["side"]."，" . $patient["sex"] . "，" . $patient["age"] . "岁。[诊断--" . $patient["diagnosis"] . "]";
        $notifyData["keyword3"] = "领料审核人：" . $user["admin_name"] . "，领料人：" . $claimer["admin_name"];
        $notifyData["keyword4"] = getCurrentDate();
        $notifyData["remark"] = null;
        $openidArray = getNotifyArrByName("auditClaim", $user["enterprise_code"]);
        array_push($openidArray, $user["openid"]);
        array_push($openidArray, $claimer["openid"]);
        $openidArray = array_unique($openidArray);
        foreach ($openidArray as $openid) {
            $notifyData["openid"] = $openid;
            ApprovalResultNotify($notifyData);
        }
        $data["message"] = $orderId;
        echo json_encode($data);
    }

    public function purchaseList() {
        $id = $_REQUEST["id"];
        $orderStatus = $_REQUEST["status"];
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $this->assign("user", $user);
        $this->assign("orderId", $id);
        $this->assign("orderStatus", $orderStatus);
        $this->display("purchaseList");
    }

    public function getPurchaseList() {

//        $map["fo.status"] = array('neq','-3');
        $status = I("post.status");
        if(!isNullOrEmpty($status)) {
            $map["ps#status"] = $status;
        }else{
            $map["ps#status-egt"] = -2;
        }
        $startdate = I("post.startdate");
        $enddate = I("post.enddate");
        if (!isNullOrEmpty($startdate)) {
            $map["ps#purchase_date-egt"] = $startdate;
        }
        if (!isNullOrEmpty($enddate)) {
            $map["ps#purchase_date-elt"] = $enddate . " 23:59:59";
        }
//
//        $month = I("post.month");
//        if (!isNullOrEmpty($month)) {
//            $map["s#outstore_date-egt"] = $month . "-01 00:00:00";
//            $map["s#outstore_date-elt"] = $month . "-30 23:59:59";
//        }

        $employee = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $map["ps.enterprise_code"] = $employee["enterprise_code"];
        $list = D("Purchase")->alias("ps")
            ->join("left join __ADMIN__ emp on emp.employee_id = ps.update_id")
            ->join("left join __ADMIN__ auditor on auditor.employee_id = ps.auditor_id")
            ->join("left join __ADMIN__ purchaser on purchaser.employee_id = ps.purchaser_id")
            ->join("left join __STORE__ s on s.store_id = ps.store_id")
            ->join("left join __SUPPLIER__ sp on sp.supplier_id = ps.supplier_id")
            ->where(getWhereSqlByMap($map))
            ->order("ps.update_time desc")
            ->field("ps.*, emp.admin_name, auditor.admin_name as auditor, purchaser.admin_name as purchaser, s.store_name, sp.supplier_name")
            ->select();
        $newList = array();
        foreach ($list as $order){
            if($order["type"] == "成品矫形器"){
                $orderList = D("PurchaseFinishedProduct")->alias("psfp")
                    ->join("left join __ADMIN__ emp on emp.employee_id = psfp.update_id")
                    ->join("left join __FINISHED_PRODUCT__ fp on fp.finished_product_id = psfp.finished_product_id")
                    ->join("left join __CLASS__ cl on cl.class_id = fp.class_id")
                    ->join("left join __SUPPLIER__ sl on sl.supplier_id = fp.supplier_id")
                    ->where(array('psfp.purchase_no'=>$order["purchase_no"]))
                    ->order("psfp.purchase_finished_product_id asc")
                    ->field("psfp.*, emp.admin_name, fp.name, fp.class_id, fp.unit, sl.supplier_name, fp.image_url, cl.class_name")
                    ->select();
                $order["orderList"] = $orderList;
            }
            if($order["type"] == "物料"){
                $orderList = D("PurchaseMaterial")->alias("psm")
                    ->join("left join __ADMIN__ emp on emp.employee_id = psm.update_id")
                    ->join("left join __CODE__ c on c.code_id = psm.code_id")
                    ->join("left join __CODE__ p on p.code_id = c.parentid")
                    ->join("left join __MATERIAL__ m on m.code_id = psm.code_id")
                    ->where(array('psm.purchase_no'=>$order["purchase_no"]))
                    ->order("psm.purchase_material_id asc")
                    ->field("psm.*, emp.admin_name, c.name as code_name, p.name as parent_name, m.material_name, m.spec, m.prop, m.unit, m.barcode")
                    ->select();

                $order["orderList"] = $orderList;
            }
            array_push($newList, $order);
        }

        echo json_encode($newList);

    }

    public function auditPurchase() {
        $status = I("post.status");
        $orderId = I("post.orderId");
        $data["code"] = 200;
        $user = D("admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $data["message"] = $orderId;
        $purchaseData = D("Purchase")->queryById($orderId);
        if($purchaseData["status"] == $status){
            $data["message"] = "采购单已审核过，无需重复审核。";
            echo json_encode($data);
            return;
        }

        if($status == 1){
            $List = D("PurchaseMaterial")->where(array('purchase_no'=>$purchaseData["purchase_no"]))->select();
            foreach ($List as $tmpData){
                $tmpData["store_id"] = $purchaseData["store_id"];
                $tmpData["supplier_id"] = $purchaseData["supplier_id"];
                $tmpData["type"] = "物料";
                $tmpStorage = D("Storage")
                    ->where(array('type'=>'物料',
                        'enterprise_code'=>$user["enterprise_code"],
                        'code_id'=>$tmpData["code_id"],
                        'store_id'=>$tmpData["store_id"],
                        'supplier_id'=>$tmpData["supplier_id"],
//                        'price'=>$tmpData["price"],
                        'batch_no'=>$tmpData["batch_no"]))
                    ->find();
                if(isNullOrEmpty($tmpStorage)){
                    $tmpData["storage_number"] = $tmpData["number"];
                    D("Storage")->add($tmpData);
                }else{
                    $totalPrice = ($tmpStorage["price"] * $tmpStorage["storage_number"]) + ($tmpData["price"] * $tmpData["number"]);
                    $tmpStorage["storage_number"] += $tmpData["number"];
                    $tmpStorage["price"] = $totalPrice / $tmpStorage["storage_number"];
                    $tmpStorage["update_time"] = getCurrentDate();
                    $tmpStorage["update_id"] = $user["employee_id"];
                    D("Storage")->updateInfo($tmpStorage);
                }

                //计算平均成本
                $allItemList = D("Storage")
                    ->where(array('type'=>'物料',
                        'enterprise_code'=>$user["enterprise_code"],
                        'code_id'=>$tmpData["code_id"],
                        'store_id'=>$tmpData["store_id"],
                    ))
                    ->select();
                $totalItemPrice = 0;
                $totalItemNumber = 0;
                foreach ($allItemList as $tmpItem){
                    $totalItemPrice += ($tmpItem["price"] * $tmpItem["storage_number"]);
                    $totalItemNumber += $tmpItem["storage_number"];
                }
                $averagePrice = $totalItemPrice/$totalItemNumber;
                foreach ($allItemList as $tmpItem){
                    $tmpItem["price"] = sprintf("%.5f", $averagePrice);
                    D("Storage")->updateInfo($tmpItem);
                }
            }
        }
        if($status == -2){
            $List = D("PurchaseMaterial")->where(array('purchase_no'=>$purchaseData["purchase_no"]))->select();
            foreach ($List as $tmpData){
                $tmpData["store_id"] = $purchaseData["store_id"];
                $tmpData["supplier_id"] = $purchaseData["supplier_id"];
                $tmpData["type"] = "物料";
                $tmpStorage = D("Storage")
                    ->where(array('type'=>'物料',
                        'enterprise_code'=>$user["enterprise_code"],
                        'code_id'=>$tmpData["code_id"],
                        'store_id'=>$tmpData["store_id"],
                        'supplier_id'=>$tmpData["supplier_id"],
//                        'price'=>$tmpData["price"],
                        'batch_no'=>$tmpData["batch_no"]))
                    ->find();
                if(!isNullOrEmpty($tmpStorage)){
                    if($tmpStorage["storage_number"] == $tmpData["number"]){
                        D("Storage")->where(array("storage_id" => $tmpStorage["storage_id"]))->delete();
                    }else{
//                        $totalPrice = ($tmpStorage["price"] * $tmpStorage["storage_number"]) - ($tmpData["price"] * $tmpData["number"]);
                        $tmpStorage["storage_number"] -= $tmpData["number"];
//                        $tmpStorage["price"] = $totalPrice / $tmpStorage["storage_number"];
                        $tmpStorage["update_time"] = getCurrentDate();
                        $tmpStorage["update_id"] = $user["employee_id"];
                        D("Storage")->updateInfo($tmpStorage);
                    }
                }else{
                    $tmpData["store_id"] = $purchaseData["store_id"];
                    $tmpData["supplier_id"] = $purchaseData["supplier_id"];
                    $tmpData["type"] = "物料";
                    $tmpData["storage_number"] *= -1;
                    $tmpData["create_time"] = getCurrentDate();
                    $tmpData["update_time"] = getCurrentDate();
                    $tmpData["update_id"] = $user["employee_id"];
                    $tmpData["storage_number"] = $tmpData["number"];
                    D("Storage")->add($tmpData);
                }

                //计算平均成本
                $allItemList = D("Storage")
                    ->where(array('type'=>'物料',
                        'enterprise_code'=>$user["enterprise_code"],
                        'code_id'=>$tmpData["code_id"],
                        'store_id'=>$tmpData["store_id"],
                    ))
                    ->select();
                $totalItemPrice = ($tmpStorage["price"] - $tmpData["price"]) * $tmpData["number"] ;
                $totalItemNumber = 0;
                foreach ($allItemList as $tmpItem){
                    $totalItemPrice += ($tmpItem["price"] * $tmpItem["storage_number"]);
                    $totalItemNumber += $tmpItem["storage_number"];
                }
                $averagePrice = $totalItemPrice/$totalItemNumber;
                foreach ($allItemList as $tmpItem){
                    $tmpItem["price"] = sprintf("%.5f", $averagePrice);
                    D("Storage")->updateInfo($tmpItem);
                }
            }
        }


        $purchaseData["status"] = $status;
        $purchaseData["auditor_id"] = $user["employee_id"];
        $purchaseData["update_time"] = getCurrentDate();
        D("Purchase")->updateInfo($purchaseData);
        $purchaser = D("admin")->where(array('employee_id'=>$purchaseData["purchaser_id"]))->find();
        if($status == 1) {
            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/audit/purchaseList/?id=" . $purchaseData["purchase_id"] . "&status=1";
            $notifyData["first"] = "采购单 [" . $purchaseData["workorder_no"] ."] 审核通过。";
            $notifyData["keyword2"] = "审核通过";
        }else{
            $notifyData["url"] = "http://".C('WEB_HOST')."/wechat/audit/purchaseList/?id=" . $purchaseData["purchase_id"] . "&status=-2";
            $notifyData["first"] = "采购单 [" . $purchaseData["workorder_no"] ."] 反审核。";
            $notifyData["keyword2"] = "反审核";
        }
        $notifyData["keyword1"] = "采购类型：" . $purchaseData["type"];
        $notifyData["keyword3"] = "采购审核人：" . $user["admin_name"] . "，采购人：" . $purchaser["admin_name"];
        $notifyData["keyword4"] = getCurrentDate();
        $notifyData["remark"] = null;
        $openidArray = getNotifyArrByName("auditPurchase", $user["enterprise_code"]);
        array_push($openidArray, $user["openid"]);
        array_push($openidArray, $purchaser["openid"]);
        $openidArray = array_unique($openidArray);
        foreach ($openidArray as $openid) {
            $notifyData["openid"] = $openid;
            ApprovalResultNotify($notifyData);
        }
        $data["message"] = $orderId;
        echo json_encode($data);
    }
}